package com.houweishi.module.wageOperateHistroy.service.impl;

import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.utils.DateUtils;
import com.houweishi.module.wageOperate.domain.RenewalSearchVO;
import com.houweishi.module.wageOperateHistroy.domain.WageOperateHistory;
import com.houweishi.module.wageOperateHistroy.mapper.WageOperateHistoryMapper;
import com.houweishi.module.wageOperateHistroy.service.IWageOperateHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 工资计算历史Service业务层处理
 * 
 * @author yqq
 * @date 2023-06-26
 */
@Service
public class WageOperateHistoryServiceImpl implements IWageOperateHistoryService 
{
    @Autowired
    private WageOperateHistoryMapper wageOperateHistoryMapper;

    /**
     * 查询工资计算历史
     * 
     * @param id 工资计算历史主键
     * @return 工资计算历史
     */
    @Override
    public WageOperateHistory selectWageOperateHistoryById(Long id)
    {
        return wageOperateHistoryMapper.selectWageOperateHistoryById(id);
    }

    /**
     * 查询工资计算历史列表
     * 
     * @param wageOperateHistory 工资计算历史
     * @return 工资计算历史
     */
    @Override
    public List<WageOperateHistory> selectWageOperateHistoryList(WageOperateHistory wageOperateHistory)
    {
        return wageOperateHistoryMapper.selectWageOperateHistoryList(wageOperateHistory);
    }

    /**
     * 新增工资计算历史
     * 
     * @param wageOperateHistory 工资计算历史
     * @return 结果
     */
    @Override
    public int insertWageOperateHistory(WageOperateHistory wageOperateHistory)
    {
        wageOperateHistory.setCreateTime(DateUtils.getNowDate());
        return wageOperateHistoryMapper.insertWageOperateHistory(wageOperateHistory);
    }

    /**
     * 修改工资计算历史
     * 
     * @param wageOperateHistory 工资计算历史
     * @return 结果
     */
    @Override
    public int updateWageOperateHistory(WageOperateHistory wageOperateHistory)
    {
        wageOperateHistory.setUpdateTime(DateUtils.getNowDate());
        return wageOperateHistoryMapper.updateWageOperateHistory(wageOperateHistory);
    }

    /**
     * 批量删除工资计算历史
     * 
     * @param ids 需要删除的工资计算历史主键
     * @return 结果
     */
    @Override
    public int deleteWageOperateHistoryByIds(Long[] ids)
    {
        return wageOperateHistoryMapper.deleteWageOperateHistoryByIds(ids);
    }

    /**
     * 删除工资计算历史信息
     * 
     * @param id 工资计算历史主键
     * @return 结果
     */
    @Override
    public int deleteWageOperateHistoryById(Long id)
    {
        return wageOperateHistoryMapper.deleteWageOperateHistoryById(id);
    }

    /**
     * 删除工资计算历史信息
     * @param company 公司
     * @param attendanceDate 考勤月份
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteWageOperateHistoryByCompanyAndAttendanceDate(String company, String attendanceDate) {
        wageOperateHistoryMapper.deleteWageOperateHistoryByCompanyAndAttendanceDate(company,attendanceDate);
    }

    /**
     * 批量新增工资历史记录
     * @param wageOperateHistoryList 工资计算
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult insertBathWageOperateHistory(List<WageOperateHistory> wageOperateHistoryList) {
        wageOperateHistoryMapper.insertBathWageOperateHistory(wageOperateHistoryList);
        return AjaxResult.success();
    }

    /**
     * 公开当月薪资
     * @param renewalSearchVO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public AjaxResult publicToStaff(RenewalSearchVO renewalSearchVO) {
        wageOperateHistoryMapper.publicToStaff(renewalSearchVO.getCompany(),renewalSearchVO.getRenewalDate());
        return AjaxResult.success();
    }

}
